$(function(){
	activeNav($("#ask-voice"));
	
	$('#reply-close').click(function(){
		$('#reply-body').hide();
		$('#replyContent').val('');
	});
	$('#reply-cancel').click(function(){
		$('#reply-body').hide();
		$('#replyContent').val('');
	});
	
	$('#reply-publish').click(function(){
		$("#replyContent").focus();
		var replyContent = $('#replyContent').val().trim();
		var voiceId = $('#voiceId').val();
		if(replyContent.length > 0){
			$.ajax({
				async: false,
				cache: false,
				dataType:'JSON',
				type:'POST',
				url: ctx + '/admin/voiceAsk/ajaxSaveReply',
				data:{voiceId:voiceId,replyContent:replyContent},
				beforeSend:function(){
					$('.dialog-win').mask('消息发送中，请稍后...');
				},
				success:function(data){
					$('.dialog-win').unmask();
					$('#reply-body').hide();
					$('#replyContent').val('');
					if(data.success){
						$('#reply-state-' + voiceId).text('已回复');
					}
					$.alert({message:data.msg});
				},
				error:function(){
					$('.dialog-win').unmask();
				}
			});
		}
	});
});

media = new Audio();

function paly(url, id) {
	media.src = ctx + url;
	media.load();
	media.play();
	$.post(ctx + "/admin/voiceAsk/ajaxRead", {id: id});
}

function reply(id){
	$('#reply-content').html('');
	$('#reply-body').show();
	$('#voiceId').val(id);
	$.ajax({
		async: false,
		cache: false,
		dataType:'JSON',
		type:'POST',
		url: ctx + '/admin/voiceAsk/ajaxReplyList',
		data:{voiceId:id},
		beforeSend:function(){
			$('.dialog-win').mask('消息加载中，请稍后...');
		},
		success:function(data){
			var list = data.list;
			var html = new Array();
			if(list.length > 0){
				$(list).each(function(i,obj){
					var time = new Date(obj.replyTime).format('yyyy-MM-dd HH:mm:ss');
					html.push('<p class="text-left">');
					html.push('<b style="color: #09c;">' + time + '</b>');
					html.push('<br />');
					html.push('<span style="margin-left: 20px;">' + obj.replyContent + '</span>');
					html.push('</p>');
				});
			} else {
				html.push('<p class="text-center" style="color: #09c;">还没有回复哦~</p>');
			}
			$('#reply-content').html(html.join(''));
			$('.dialog-win').unmask();
		},
		error:function(){
			$('.dialog-win').unmask();
		}
	});
}